#ifndef LINENUMBERINGPUSHBACKREADER_H
#define LINENUMBERINGPUSHBACKREADER_H

/**
 * Copyright (c) Rich Hickey. All rights reserved.
 * The use and distribution terms for this software are covered by the
 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 * which can be found in the file epl-v10.html at the root of this distribution.
 * By using this software in any fashion, you are agreeing to be bound by
 * the terms of this license.
 * You must not remove this notice, or any other, from this software.
 */

#include <QIODevice>
namespace clojure_lang {

class LineNumberingPushbackReader : public QIODevice
{
    Q_OBJECT
private:
    QIODevice *_base;
    bool _ownership;

    static const char newline = '\n';
    bool _atLineStart;
    bool _prev;
    int _lineNumber;
    int _prevColumnNumber;
    int _columnNumber;
    bool _prevLineStart;
    int _index;

    void noteLineAdvance();
protected:
    virtual qint64 readData(char *data, qint64 maxlen);
    virtual qint64 writeData(const char *data, qint64 len);

public:
    explicit LineNumberingPushbackReader(QObject *parent = 0);
    LineNumberingPushbackReader(QIODevice *base, bool ownership = true);

    virtual int read();
    virtual void unread(int chr);

    int index();
    int columnNumber();
    int lineNumber();
    int peek();
    bool atLineStart();
    QString readLine();


    virtual ~LineNumberingPushbackReader();
signals:

public slots:

};
}
#endif // LINENUMBERINGPUSHBACKREADER_H
